package com.geekaca.d09;

import java.io.File;

public class TestFileSearch {
    public static void main(String[] args) {
        File filepath = new File("F:\\Geeka\\lh\\JavaSE_Senior\\day09\\StudyIO1\\src");
        searchFile(filepath, ".java");
    }

    public static void searchFile(File dir, String toSerachName) {
        if (dir != null && dir.isDirectory()) {
            File[] files = dir.listFiles();

            if (files.length != 0) {
                for (int i = 0; i < files.length; i++) {
                    File curFile = files[i];
                    if (curFile.isFile()) {
                        System.out.println(curFile.getAbsolutePath() + " 是文件");
                        if (curFile.getName().contains(toSerachName)) {
                            System.out.println("找到文件: " + curFile.getAbsolutePath());

                        }
                    } else {
                        System.out.println(curFile.getAbsolutePath() + " 是文件夹");
                        searchFile(curFile, toSerachName);
                    }

                }
            }
        }
    }
}
